<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/3/28
 * Time: 10:43
 */
namespace common\sources\write\taskcommodkeywords;

use common\models\craftsman\TaskCommodKeywords;
use Yii;

class TaskCommodKeywordAccess
{
    public function addTaskCommodKeyword($data)
    {
        $connect  = Yii::$app->db;
        $queryBuilder = $connect->queryBuilder;
        $sql = $queryBuilder->batchInsert(TaskCommodKeywords::tableName(),['bus_id','task_commod_id','word','num','create_time'],$data);
       return $connect->createCommand($sql)->execute();
    }

    public function delTaskCommodKeyword($task_commod_id)
    {
        return TaskCommodKeywords::deleteAll(['task_commod_id' => $task_commod_id]);
    }

    public function ModifyTaskKeyWords($data) {
        $keyword = TaskCommodKeywords::findOne(['id' => $data['id']]);
        if ($keyword) {
            $keyword->word = $data['keywords'];
            if ($keyword->save()) {
                return true;
            }
        }
        return false;
    }

	//修改关键字使用次数
	public function modifyTaskCommodKeyword($data) {
		$sql = 'UPDATE ' . TaskCommodKeywords::tableName() . ' SET use_num = :use_num,update_time = :update_time WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':use_num'     => $data['use_num'],
				':update_time' => time(),
				':id'          => $data['task_commod_keyword_id']
			])->execute();
	}
}